Flash Remoting Article

Introduction to Flash Remoting with .NET


Table of Contents

  1. Introduction
  2. Overview of .NET with Flash Remoting
  3. Connecting ASP.NET to Flash Remoting
  4. Manipulating ASP.NET with Flash

Connecting ASP.NET to Flash Remoting

For Flash Remoting to communicate with an ASP.NET page ensure that you have installed Flash Remoting on your web server machine. (See the Requirements section of this tutorial.) You will also need Internet Information Server and the .NET framework running on that machine. If everything is installed properly, Flash Remoting will create a sample directory named flashremoting on the web server. This example directory will house this article’s Flash application and ASP.NET pages.

To create a separate website or directory that uses Flash Remoting, open a new site with Internet Information Server and copy the contents of flashremoting/bin into the new website’s bin directory. This will copy the server control and registration information that Flash Remoting needs to work. Also note that Flash Remoting generates a Flash.log file when an error occurs. Viewing this log will provide a description of any connectivity errors you encounter to ease troubleshooting.

As a reference, here is a list of the files you will need in the flashremoting directory:

bin/flashgateway.dll
FlashRemotingService.aspx
gateway.aspx

To get started, open Dreamweaver MX 2004 or your preferred ASP.NET development environment and create a new file named FlashRemotingService.aspx. This ASP.NET page works as a remote service that you will later manipulate in Flash. In this article, I use C# for example, but you can recreate the code in VBScript or JavaScript. I also reference the Flash Remoting Server Control, an ASP.NET assembly that gives the ASP.NET page access to parameters and lets it return data to the Flash application.

<%@ Page Language="C#" debug="true" %>
<%@ Register TagPrefix="MM" Namespace="FlashGateway" Assembly="flashgateway" %>
<html>
<head>
  <title>jasonmperry.com  Flash Remoting Example</title>
</head>

<body bgcolor="#ffffff" text="#000000">
</body>
</html>

For ASP.NET developers, the above code appears to be basic except for the addition of one declaration, Register. This declaration registers the Flash Remoting server control flashgateway.dll for the ASP.NET page. Flash Remoting will use this gateway to get parameters from the Flash application and return any results back to the application.

Now that the server control is registered on the page, create a new instance of this control by adding the following tag to the HTML body tag:

<body bgcolor="#ffffff" text="#000000">
<MM:Flash id="Flash" runat="server" />
</body>
	

This tag, similar to other ASP.NET server controls, uses the ID to create a programmatic reference to the assembly. Notice the tag uses an MM prefix like the value you used in the Register declaration. This tag does not embed a Flash file into the page; it only creates an instance for use in Flash Remoting.

You can now access Flash parameters and pass a result to your Flash interface using the Flash Server Control. To do this, add the Page_Load callback function as follows:

<script language="C#" runat="server">
void Page_Load( Object sender, EventArgs e)
{
	string name = "";

	if( Flash.Params.Count > 0 )
	{
	  name = Flash.Params[0].ToString();
	}

	Flash.Result = "Hello" + name + "Welcome to Flash Remoting!";
}
</script>

This script determines if parameters were passed from the Flash interface. If so, it gets the first parameters as a string. It uses the string value to combine a more complex string to the returned value.